<?php
namespace app\erp\controller;

use app\erp\model\OutlinkCategorydb;

class OutlinkCategory extends Base
{

    protected $db;

    protected $cols = array(
        array(
            'field' => 'outlink_category_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'outlink_category_id',
            'width' => 120,
            'title' => '分类编号'
        ),
        array(
            'field' => 'category_name',
            'width' => 200,
            'title' => '分类名称',
            'sort' => 'true',
            'edit' => 'true'
        ),
        array(
            'fixed' => 'right',
            'width' => 80,
            'toolbar' => '#outlink_category_tool'
        )
    );

    public $post = array();

    public function _initialize()
    {
        parent::_initialize();
        $request = request();
        $param = $request->param();
        $this->post = $param;
        $this->db = new OutlinkCategorydb();
    }

    public function index()
    {
        $this->assign('cols', json_encode($this->cols));
        return $this->fetch();
    }

    /**
     *
     * @todo 列表
     */
    public function ajaxList()
    {
        $this->db->param = $this->post;
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return['data'], $return['count']);
    }

    public function tplForm()
    {
        $outlink_category_id = 0;
        $data = array();
        if (isset($this->post['outlink_category_id'])) {
            $data = $this->db->ajaxFind($this->post['outlink_category_id']);
            $outlink_category_id = $this->post['outlink_category_id'];
        }
        $this->assign('data', json_encode($data));
        $this->assign('outlink_category_id', $outlink_category_id);
        return $this->fetch();
    }

    /**
     *
     * @todo 保存数据
     */
    public function saveData()
    {
        $this->db->param = $this->post;
        $return = $this->db->ajaxSave();
        if ($return != 'success') {
            $this->layuiReturn($return, 0, $return, - 1);
        } else {
            $this->layuiReturn('保存成功');
        }
    }

    /**
     *
     * @todo 软删除
     */
    public function ajaxDelete()
    {
        $this->db->param = $this->post;
        $this->db->ajaxDelete();
        $this->layuiReturn('删除成功', 0);
    }
}